package com.njust.RateMyTray_backend.controller;

import com.njust.RateMyTray_backend.common.Result;
import com.njust.RateMyTray_backend.dto.WindowQueryDTO;
import com.njust.RateMyTray_backend.service.WindowService;
import com.njust.RateMyTray_backend.vo.WindowDetailVO;
import com.njust.RateMyTray_backend.vo.WindowListVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/windows")
public class WindowController {

    @Autowired
    private WindowService windowService;

    @GetMapping
    public ResponseEntity<Result<WindowListVO>> getWindowList(WindowQueryDTO queryDTO) {
        log.info("获取窗口列表，查询参数: {}", queryDTO);
        WindowListVO windowList = windowService.getWindowList(queryDTO);
        Result<WindowListVO> result = Result.success(200, "获取窗口列表成功", windowList);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @GetMapping("/{windowId}")
    public ResponseEntity<Result<WindowDetailVO>> getWindowDetails(@PathVariable Long windowId) {
        log.info("获取窗口 {} 的详细信息", windowId);
        WindowDetailVO windowDetails = windowService.getWindowDetails(windowId);
        Result<WindowDetailVO> result = Result.success(200, "获取窗口详情成功", windowDetails);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
} 